<?php

namespace App\Providers;

use App\Http\Responses\Code;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Response;
use Illuminate\Http\JsonResponse;

class ResponseServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Response::macro('success', function ($data = [], $code = Code::OK) {
            return new JsonResponse([
                'code' => $code,
                'message' => 'success',
                'data' => $data,
            ]);
        });

        Response::macro('failed', function ($message = 'error', $code = 10000) {
            return new JsonResponse([
                'code' => $code,
                'message' => $message,
                'data' => [],
            ]);
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
